package com.ekalenchuk.module.service.secutiry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.ekalenchuk.module.exception.entity.NotFoundException;
import com.ekalenchuk.module.service.user.UserService;

public class CustomUserDetailsManager implements UserDetailsService {

	@Autowired
	private UserService userService;

    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        try {
			return userService.getUserDetails(username);
		} catch (NotFoundException e) {
			throw new UsernameNotFoundException(e.getMessage());
		}
    }
}
